﻿Public Class ucEmpresaPesquisa
#Region "Eventos públicos acessados pelo formulário de cadastro"
    Public Event Incluir()
    Public Event Sair()
    Public Event Visualizar(ByVal estoquelocal As Model.Pessoa)
#End Region

#Region "Metodos privados do UC"
    Private Sub Pesquisa()
        Dim ctrl As New Control.Empresa

        bsEmpresa.DataSource = ctrl.ListaByDescricao(txtDescricao.Text)
        dvgEmpresa.DataSource = bsEmpresa
    End Sub

    Private Sub Excluir()
        If CType(bsEmpresa.Current, Model.Pessoa) IsNot Nothing Then
            Dim control As New Control.Empresa
            If Dialog.QuestionYesNo("Deseja realmente remover este registro?") = Windows.Forms.DialogResult.Yes And Not bsEmpresa.Current Is Nothing Then
                If Not control.Excluir(CType(bsEmpresa.Current, Model.Pessoa)) Then
                    MessageBox.Show("Não foi possivel remover pois há relacionamentos.")
                End If
            End If

            control = Nothing
            Pesquisa()
        End If
    End Sub

    Private Sub Visualiza()
        If CType(bsEmpresa.Current, Model.Pessoa) IsNot Nothing Then
            RaiseEvent Visualizar(CType(bsEmpresa.Current, Model.Pessoa))
        End If
    End Sub
#End Region

#Region "Eventos privados dos objetos visuais"
    Private Sub btnIncluir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIncluir.Click
        RaiseEvent Incluir()
    End Sub

    Private Sub btnVisualizar_Click(sender As Object, e As EventArgs) Handles btnVisualizar.Click
        Visualiza()
    End Sub

    Private Sub btnPesquisar_Click(sender As Object, e As EventArgs) Handles btnPesquisar.Click
        Pesquisa()
    End Sub

    Private Sub btnSair_Click(sender As Object, e As EventArgs) Handles btnSair.Click
        RaiseEvent Sair()
    End Sub

    Private Sub dvgEstoqueLocal_KeyDown(sender As Object, e As KeyEventArgs) Handles dvgEmpresa.KeyDown
        Visualiza()
    End Sub

    Private Sub dvgEstoqueLocal_DoubleClick(sender As Object, e As EventArgs) Handles dvgEmpresa.DoubleClick
        Visualiza()
    End Sub

    Private Sub btnExcluir_Click(sender As Object, e As EventArgs) Handles btnExcluir.Click
        Excluir()
    End Sub
#End Region




End Class
